const { click_el } = require('../utils/utils.js');

let devuceWidth = device.width;
let devuceHeight = device.height;

// 截图
const commandScreenshot = () => {
  return takeScreenshot();
}

// 根据控件进行点击/ocr
const commandClick = (el, index) => {
  return click_el(el, index);
}

// 根据坐标进行点击
const commandClickByCoordinate = (xy) => {
  let [x,y] = xy.split(',');
  press(x, y, 100)
}


// 左滑
const commandSwipeLeft = () => {
  let centerWidth = devuceWidth / 2;
  let centerHeight = devuceHeight / 2;
  return swipe(centerWidth + 80, centerHeight, centerWidth - 80, centerHeight, 500);
}

// 右滑
const commandSwipeRight = () => {
  let centerWidth = devuceWidth / 2;
  let centerHeight = devuceHeight / 2;
  return swipe(centerWidth - 80, centerHeight, centerWidth + 80, centerHeight, 500);
}

// 上滑
const commandSwipeUp = () => {
  let centerWidth = devuceWidth / 2;
  let centerHeight = devuceHeight / 2;
  return swipe(centerWidth, centerHeight + 80, centerWidth, centerHeight - 80, 500);
}
// 下滑
const commandSwipeDown = () => {
  let centerWidth = devuceWidth / 2;
  let centerHeight = devuceHeight / 2;
  return swipe(centerWidth, centerHeight - 80, centerWidth, centerHeight + 80, 500);
}

// 打开app
const commandOpenApp = (name) => {
  return app.launchApp(name)
}

// 返回
const commandBack = () => {
  return back();
}

// 返回桌面
const commandHome = () => {
  return home();
}

module.exports = { 
  commandScreenshot, 
  commandClick, 
  commandSwipeLeft, 
  commandSwipeRight, 
  commandSwipeUp, 
  commandSwipeDown, 
  commandOpenApp, 
  commandClickByCoordinate,
  commandBack,
  commandHome
}
